from strategy_mode import dataLoader, str_cal, Trading, TradingRules

# 上涨模式
def UpMode(
    df_day, df_day_1, preTYPES, mode, tradePersent, day_lists, day, statsdic, count_in
):

    return mode, tradePersent


# 下跌模式
def DownMode(
    df_day, df_day_1, preTYPES, mode, tradePersent, day_lists, day, statsdic, count_in
):

    return mode, tradePersent


def RoundMode(
    df_day, df_day_1, preTYPES, mode, tradePersent, day_lists, day, statsdic, count_in
):

    return mode, tradePersent


def Main(
    df_day,
    df_day_1,
    mode="BUY/SELL",
    line_Pares=5,
    tradePersent=1,
    day_lists=[],
    day=0,
    statsdic={},
    count_in=1,
):

    gap = 4 / len(day_lists)
    types = statsdic["TYPES"]
    tradePersent = 0

    if (
        df_day["open_sort"] < 0
        and df_day["close_sort"] < 0
        and df_day["low_sort"] < 0
        and df_day["high_sort"] < 0
    ) and (
        df_day["open_by%Boll_sum"] < 0
        and df_day["close_by%Boll_sum"] < 0
        and df_day["low_by%Boll_sum"] < 0
        and df_day["high_by%Boll_sum"] < 0
    ):
        types = "LOW"

    elif (
        df_day["open_sort"] > 0
        and df_day["close_sort"] > 0
        and df_day["low_sort"] > 0
        and df_day["high_sort"] > 0
    ) and (
        df_day["open_by%Boll_sum"] > 0
        and df_day["close_by%Boll_sum"] > 0
        and df_day["low_by%Boll_sum"] > 0
        and df_day["high_by%Boll_sum"] > 0
    ):  # 上涨模式
        types = "HIGH"

    else:  # 横盘模式
        types = "ROUND"

    # TODO 增加循环判断节,解决连续下跌止损问题

    for col in df_day.index.tolist():
        if "All" in col:
            if "All_by%Boll_sum" in col:
                if "rolling" not in col:
                    sum_All = col
                elif "up" in col:
                    sum_up = col
                elif "down" in col:
                    sum_down = col
                elif "T" in col:
                    sum_rolling = col
            elif "All_sort" in col:
                if "rolling" not in col:
                    sort_All = col
                elif "up" in col:
                    sort_up = col
                elif "down" in col:
                    sort_down = col
                elif "T" in col:
                    sort_rolling = col
    if (
        (
            df_day_1[sum_rolling] > df_day_1[sum_down]
            and df_day[sum_rolling] < df_day[sum_down]
            # and df_day[sort_rolling] < df_day[sort_down]
            and df_day[sum_rolling] < 0
        )
        or (
            df_day_1[sum_rolling] > df_day_1[sum_down]
            and df_day[sum_rolling] < df_day[sum_down]
            # and df_day[sort_rolling] < df_day[sort_down]
            and df_day[sum_rolling] > 0
        )
        # or (
        #     df_day_1[sort_rolling] < df_day_1[sort_down]
        #     and df_day[sort_rolling] > df_day[sort_down]
        #     and df_day[sum_rolling] < df_day[sum_down]
        #     and df_day[sort_rolling] < 0
        # )
        # or (
        #     df_day_1[sort_rolling] > df_day_1[sort_down]
        #     and df_day[sort_rolling] < df_day[sort_down]
        #     and df_day[sum_rolling] < df_day[sum_down]
        #     and df_day[sort_rolling] > 0
        # )
    ):

        mode = "BUY"
        tradePersent = 0.5
    elif (
        (
            df_day_1[sum_rolling] < df_day_1[sum_up]
            and df_day[sum_rolling] > df_day[sum_up]
            # and df_day[sort_rolling] < df_day[sort_up]
            and df_day[sum_rolling] < 0
        )
        or (
            df_day_1[sort_rolling] > df_day_1[sum_up]
            and df_day[sort_rolling] < df_day[sum_up]
            # and df_day[sum_rolling] > df_day[sort_up]
            and df_day[sort_rolling] > 0
        )
        # or (
        #     df_day_1[sort_rolling] < df_day_1[sort_up]
        #     and df_day[sort_rolling] > df_day[sort_up]
        #     and df_day[sum_rolling] < df_day[sum_up]
        #     and df_day[sort_rolling] < 0
        # )
        # or (
        #     df_day_1[sum_rolling] > df_day_1[sort_up]
        #     and df_day[sum_rolling] < df_day[sort_up]
        #     and df_day[sort_rolling] > df_day[sum_up]
        #     and df_day[sum_rolling] > 0
        # )
    ):

        mode = "SELL"
        tradePersent = 0.5

    statsdic["TYPES"] = types
    return mode, tradePersent, statsdic
